home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / modula2 / 259 < prev    next >
Encoding:
Text File  |  1996-08-06  |  4.4 KB  |  169 lines

  1. Path: nntp.nta.no!usenet
  2. From: torbjorn.sund@fou.telenor.no (Torbj°rn Sund)
  3. Newsgroups: comp.lang.modula2
  4. Subject: Re: Reading Floppies.
  5. Date: 6 Feb 1996 11:12:06 GMT
  6. Organization: Telenor R&D, Troms°, Norway
  7. Distribution: world
  8. Message-ID: <4f7d26$bmh@nntp.nta.no>
  9. References: <1996Feb1.125721.18589@ucl.ac.uk>
  10. Reply-To: torbjorn.sund@fou.telenor.no (Torbj°rn Sund)
  11. NNTP-Posting-Host: grim.tft.tele.no
  12. X-Newsreader: IBM NewsReader/2 v1.9d - NLS
  13.  
  14. In <1996Feb1.125721.18589@ucl.ac.uk>, zcaccau@cs.ucl.ac.uk (Chris Austin) writes:
  15. >
  16. >In modula-2 is there any way that you can determine whether a floppy drive
  17. >currently contains a disk and whether it is correctly formatted,  (i.e.
  18. >whether the drive is readable), without getting the DOS abort, retry or
  19. >ignore message.  I would like this to work with CD's, IOMEGA ZipDrives,
  20. >etc... as well.
  21.  
  22. Here's an extract of my low-level BIOS and diskette access code.
  23. All in Modula-2 (sort of), no assembler.
  24. Note I have extracted only relevant portions, 
  25. complain to me if I missed something out.
  26. Written for Topspeed M2, but all the non-standard constructs 
  27. have similar counterparts in the other DOS compilers.
  28. (and I've seen most under DOS).
  29.  
  30. The idea of reading from the diskette to detect if it is present
  31. is taken from a fast multitasking diskette copier supplied
  32. in source with the full JPI M2 distribution. The code is mine
  33. so there should be no copyright problems, but credit to 
  34. JPI anyway.
  35.  
  36. Hope this helps.
  37.  
  38. Cut here:
  39. - - - - - -
  40. DEFINITION MODULE BIOSFun;
  41.  
  42. CONST
  43.   MaxBytesInSector = 1024;
  44.  
  45. (* following are direct mappings from BIOS functions *)
  46.  
  47. PROCEDURE ResetDisk( DrvNo: SHORTCARD): SHORTCARD;
  48. PROCEDURE ReadSectors( DrvNo: SHORTCARD;
  49.                        VAR Buffer: ARRAY OF SHORTCARD; VAR NoSec: SHORTCARD;
  50.                        HedNo, CylNo, SecNo: SHORTCARD): SHORTCARD;
  51.  
  52. END BIOSFun.
  53.  
  54. -- and here --
  55.  
  56. IMPLEMENTATION MODULE BIOSFun;
  57.  
  58. (* Interrupt 13H, chosen functions for diskett *)
  59.  
  60. IMPORT SYSTEM, Lib;
  61. (*%T _XTD *) (* if compiled with extended (protected) memory model *)
  62.   IMPORT TSXLIB;
  63. (*%E *)
  64.  
  65. CONST Int13 = 013H;
  66.  
  67. (* function 0 *)
  68. PROCEDURE ResetDisk( DrvNo: SHORTCARD): SHORTCARD;
  69.   VAR
  70.     r: SYSTEM.Registers;
  71.   BEGIN
  72.     r.AH := 0; r.DL := DrvNo;
  73.     Lib.Intr( r, Int13);
  74.     RETURN r.AH;
  75.   END ResetDisk;
  76.  
  77. (* function 02 *)
  78. PROCEDURE ReadSectors( DrvNo: SHORTCARD;
  79.                        VAR Buffer: ARRAY OF SHORTCARD; VAR NoSec: SHORTCARD;
  80.                        HedNo, CylNo, SecNo: SHORTCARD): SHORTCARD;
  81.   VAR
  82.     r: SYSTEM.Registers;
  83.   BEGIN
  84.     WITH r DO
  85.       AH := 2;
  86.       DL := DrvNo;
  87.       AL := NoSec;
  88.       CH := CylNo;
  89.       CL := SecNo;
  90.       DH := HedNo;
  91.       ES := Seg(Buffer);
  92.       BX := Ofs(Buffer);
  93.       Lib.Intr( r, Int13);
  94.       NoSec := AL;
  95.       RETURN AH;
  96.     END;
  97.   END ReadSectors;
  98.  
  99.  
  100. BEGIN
  101. (*%T _XTD *)
  102.   TSXLIB.InitInt13();
  103. (*%E *)
  104.  
  105. END BIOSFun.
  106.  
  107. ---- and here ----
  108.  
  109. DEFINITION MODULE Diskett;
  110.  
  111. (* Utility functions for diskette *)
  112. (* Drive number should be 0 and 1 for A: and B: 
  113.     if memory serves me right, or maybe it's 1 and 2 
  114. *)
  115.  
  116. PROCEDURE DiskIsPresent( DrvNo: SHORTCARD): BOOLEAN;
  117. PROCEDURE Wait4DiskChange( DrvNo: SHORTCARD);
  118.  
  119. END Diskett.
  120.  
  121. --- and here ---
  122.  
  123. IMPLEMENTATION MODULE Diskett;
  124.  
  125. IMPORT Lib, BIOSFun;
  126.  
  127. VAR
  128.   DummyBuffer: ARRAY [0 .. BIOSFun.MaxBytesInSector-1] OF SHORTCARD;
  129.  
  130. PROCEDURE DiskIsPresent( DrvNo: SHORTCARD): BOOLEAN;
  131.   VAR
  132.     SecCnt,
  133.     result : SHORTCARD;
  134.   BEGIN
  135.     IF BIOSFun.ResetDisk( DrvNo) # 0 THEN RETURN FALSE; END;
  136.     SecCnt := 1;
  137.     result := BIOSFun.ReadSectors( DrvNo, DummyBuffer, SecCnt, 0, 0, 1);
  138.     (* yeah, I know, the result codes below should have been changed
  139.         into symbolic constants instead of magic numbers *)
  140.     RETURN (result = 0) OR (result = 2) OR (result = 3) OR (result = 4)
  141.         OR (result = 6) OR (result = 8) OR (result = 9) OR (result = 10H);
  142.   END DiskIsPresent;
  143.  
  144. PROCEDURE Wait4DiskChange( DrvNo: SHORTCARD);
  145.   VAR
  146.     SecCnt,
  147.     res : SHORTCARD;
  148.   BEGIN
  149.     (* first wait for diskette to be removed *)
  150.     REPEAT
  151.       Lib.Delay(750);
  152.       SecCnt := 1;
  153.       res := BIOSFun.ReadSectors( DrvNo, DummyBuffer, SecCnt, 0, 0, 1);
  154.     UNTIL (res=6);
  155.     (* then wait until a new one is present *)
  156.     WHILE NOT DiskIsPresent( DrvNo) DO Lib.Delay(100); END;
  157.   END Wait4DiskChange;
  158.  
  159.  
  160. END Diskett.
  161.  
  162. ---------- cut here
  163.  
  164. Torbj°rn Sund                         Telenor R&D
  165. Tel (+47) 77 61 27 87               Pb 1156, Strandgt 9
  166. Fax (+47) 77 61 27 02               N-9001 Troms°
  167. torbjorn.sund@fou.telenor.no        Norway
  168.  
  169.